package cn.iocoder.yudao.module.form.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.form.dataobject.FormDataset;
import cn.iocoder.yudao.module.form.service.IFormDatasetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 数据集Controller
 *
 * @author Fan KaiXiang
 * @date 2022-09-02
 */
@RestController
@Api(tags = "a报表数据集管理")
@RequestMapping("/admin-api/form/dataset")
public class FormDatasetController
{
    @Autowired
    private IFormDatasetService formDatasetService;

    /**
     * 查询数据集列表
     */
//    @PreAuthorize("@ss.hasPermi('form:dataset:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取数据集列表", notes = "获取数据集列表")
    public CommonResult<List<FormDataset>> list(FormDataset formDataset)
    {
//        startPage();
        List<FormDataset> list = formDatasetService.selectFormDatasetList(formDataset);
        return success(list);
    }

    /**
     * 导出数据集列表
     */
//    @PreAuthorize("@ss.hasPermi('form:dataset:export')")
//    @Log(title = "数据集", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, FormDataset formDataset)
//    {
//        List<FormDataset> list = formDatasetService.selectFormDatasetList(formDataset);
//        ExcelUtil<FormDataset> util = new ExcelUtil<FormDataset>(FormDataset.class);
//        util.exportExcel(response, list, "数据集数据");
//    }

    /**
     * 获取数据集详细信息
     */
//    @PreAuthorize("@ss.hasPermi('form:dataset:query')")
    @ApiOperation(value = "获取数据集详细信息", notes = "获取数据集详细信息")
    @GetMapping(value = "/{datasetId}")
    public CommonResult<FormDataset> getInfo(@PathVariable("datasetId") Long datasetId)
    {
        return success(formDatasetService.selectFormDatasetByDatasetId(datasetId));
    }

    /**
     * 新增数据集
     */
//    @PreAuthorize("@ss.hasPermi('form:dataset:add')")
    @ApiOperation(value = "新增数据集", notes = "新增数据集")
    @PostMapping
    public CommonResult<Integer> add(@RequestBody FormDataset formDataset)
    {
        return success(formDatasetService.insertFormDataset(formDataset));
    }

    /**
     * 修改数据集
     */
//    @PreAuthorize("@ss.hasPermi('form:dataset:edit')")
    @ApiOperation(value = "修改数据集", notes = "修改数据集")
    @PutMapping
    public CommonResult<Integer> edit(@RequestBody FormDataset formDataset)
    {
        return success(formDatasetService.updateFormDataset(formDataset));
    }

    /**
     * 删除数据集
     */
//    @PreAuthorize("@ss.hasPermi('form:dataset:remove')")
    @ApiOperation(value = "删除数据集", notes = "删除数据集")
	@DeleteMapping("/{datasetIds}")
    public CommonResult<Integer> remove(@PathVariable Long[] datasetIds)
    {
        return success(formDatasetService.deleteFormDatasetByDatasetIds(datasetIds));
    }
}
